import Taro from '@tarojs/taro';

/**
 * @description 获取当前页url
 */
export const getCurrentPageUrl = () => {
  const pages = Taro.getCurrentPages();
  const currentPage = pages[pages.length - 1];
  const url = currentPage.route;
  return url;
};

export const pageToLogin = () => {
  // const path: any = getCurrentPageUrl();
  Taro.clearStorage();
  // if (!path.includes('login')) {
  //   if (process.env.TARO_ENV === 'weapp') {
  //     Taro.reLaunch({
  //       url: '/pages/login/wxLogin/index'
  //     });
  //   } else {
  //     Taro.reLaunch({
  //       url: '/pages/login/mobileLogin/index'
  //     });
  //   }
  // }
};

export const pageTo404 = () => {
  const path: any = getCurrentPageUrl();
  if (!path.includes('404')) {
    Taro.reLaunch({
      url: '/pages/error/404/index'
    });
  }
};
